package com.xtoneict.util.utils;

import java.io.IOException;
import java.util.Calendar;

public class DateUtil {
    public Integer getMonthCount(int year, int month){
        //创建一个Calendar实例
        Calendar calendar = Calendar.getInstance();

        //设置Calendar实例的时间
        calendar.set(year, month, 1);

        int day = calendar.getActualMaximum(calendar.DAY_OF_MONTH);

        System.out.println(day);
        return day;
    }

    public char judgeIfHoliday(Integer year, Integer month, Integer day) throws IOException {
        /**
         * 0：表示前面补0
         * digit：表示保留数字位数
         * d：表示参数为正数类型
         */
        String m = String.format("%0" + 2 + "d", month);
        String d = String.format("%0" + 2 + "d",day);

        //拼接url
        String url = "http://tool.bitefu.net/jiari/?d=" + year + m + d;

        OkHttpApi api = new OkHttpApi();

        //返回参数：请求一天，返回对应节假日状态（0-工作日, 1-休息日, 2-节假日）
        String str = api.run(url);
        char res = str.charAt(0);
        System.out.println("节假日工作状态：" + res + "（0-工作日, 1-休息日, 2-节假日）");

        return res;
    }
}
